/**
 * @version 1.8
 * @Author Djx_hmbb
 * @Date 2023/8/9 16:33
 * @注释:中断是指通知线程应该停止了,但是是否停止,取决于线程的具体的代码写法
 * 1.发送终止程序的申请,但是是否终止看程序员的代码
 * 2.发送终止程序的申请,立刻终止程序
 * 3.发送终止程序的申请,等待几秒再终止程序
 */
public class ThreadDemo8 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            boolean b = Thread.currentThread().isInterrupted();
            while (!b) {
                //true终止,false不终止-->继续
                System.out.println("hello Thread!");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException interruptedException) {
                        interruptedException.printStackTrace();
                    }
                    e.printStackTrace();
                    break;
                }
            }
        });
        t.start();

        Thread.sleep(3000);
        t.interrupt();
    }
}
